using Framework.Core;
using System.Collections;
using UnityEngine.Networking;

namespace Framework
{
    public abstract class HttpRequestAgent : IReference
    {
        private static int _id = 1;
        public HttpRequestTask Task { get; private set; }
        public bool Finished { get; private set; }
        public int Id { get; private set; }
        public bool IsReferenceActive { get; set; }
        protected ICoroutineManager coroutineManager;
        public virtual void Clear()
        {
            Task = null;
        }
        public void SetCoroutineManager(ICoroutineManager value)
        {
            coroutineManager = value;
        }
        public int Send(HttpRequestTask value)
        {
            Finished = false;
            Id = _id++;
            Task = value;
            onSend();
            return Id;
        }
        public void Complete(bool error, byte[] data = null)
        {
            Task.Result.Set(error, data);
            this.Finished = true;
        }
        protected virtual void onSend()
        {

        }

    }
}